<?php
	function get_filetype($filename){ 
		if (substr_count($filename, ".") == 0){ 
			// 检查文件名中是否有.号。 
			return; // 返回空
		}else if (substr($filename, -1) == "."){
			// 检查是否以.结尾，即无扩展名 
			return; // 返回空 
		}else{ 
			$filetype = strrchr ($filename, "."); // 从.号处切割
			$filetype = substr($filetype, 1); // 去除.号 
			return $filetype; // 返回 
		} 
	}
	
	function encrypt($string, $key) { 
		for($i=0; $i<strlen($string); $i++) { 
			for($j=0; $j<strlen($key); $j++) { 
				$string[$i] = $string[$i]^$key[$j]; 
			} 
		} 
		return $string; 
	} 
	
	//解密函数
	function decrypt($string, $key) { 
		for($i=0; $i<strlen($string); $i++) { 
			for($j=0; $j<strlen($key); $j++) { 
				$string[$i] = $key[$j]^$string[$i]; 
			} 
		} 
		return $string; 
	}

/*
//示例
$my_password="chair";
echo "my_password = $my_password<br>";
$my_key="123";
$my_password_en=myEncrypt($my_password,$my_key);
echo "my_password_en = $my_password_en<br>";
$my_password_de=myDecrypt($my_password_en,$my_key);
echo "my_password_de = $my_password_de<br>";
//*/

/*结果如
my_password = chair
my_password_en = RYPXC
my_password_de = chair
//*/
	
	// 将 16 进制转换为 2 进制字符
	function _hex2bin( $hexdata ){
		$bindata = "";
		for ( $i=0; $i<strlen($hexdata); $i+=2 )
			$bindata.=chr(hexdec(substr($hexdata,$i,2)));

		return $bindata;
	}

	//UTF8 to GB2312
	function utf82gb($SourceText){
		if(trim($SourceText)=="") return $SourceText;

		$filename = dirname(__FILE__).'/gb-unicode.table';
		$tmp = @file($filename);
		$unicode_table = array();
		while(list($key,$value)=each($tmp))
		$unicode_table[hexdec(substr($value,7,6))]=substr($value,0,6);

		$out = "";
		$len = strlen($SourceText);
		$i = 0;
		while($i < $len)
		{
				$c = ord( substr( $SourceText, $i++, 1 ) );
				switch($c >> 4)
				{ 
					case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
						// 0xxxxxxx
						$out .= substr( $SourceText, $i-1, 1 );
					break;
					case 12: case 13:
						// 110x xxxx   10xx xxxx
						$char2 = ord( substr( $SourceText, $i++, 1 ) );
						$char3 = $unicode_table[(($c & 0x1F) << 6) | ($char2 & 0x3F)];

						$out .= _hex2bin( dechex(  $char3 + 0x8080 ) );

					break;
					case 14:
						// 1110 xxxx  10xx xxxx  10xx xxxx
						$char2 = ord( substr( $SourceText, $i++, 1 ) );
						$char3 = ord( substr( $SourceText, $i++, 1 ) );
						$char4 = $unicode_table[(($c & 0x0F) << 12) | (($char2 & 0x3F) << 6) | (($char3 & 0x3F) << 0)];

						$out .= _hex2bin( dechex ( $char4 + 0x8080 ) );
					break;
				}
		}
		return $out;
	}

?>